<?php

declare(strict_types=1);

namespace Modules\Production\Models;

use Modules\Base\Models\BoxNumber;
use Modules\Base\Models\Material;
use Catch\Base\CatchModel as Model;

/**
 * @property $id
 * @property $report_order_id
 * @property $lot_num
 * @property $qty
 * @property $material_no
 * @property $creator_id
 * @property $created_at
 * @property $updated_at
 * @property $deleted_at
*/
class ReportOrderBox extends Model
{


    protected $table = 'report_order_box';

    protected $fillable = [ 'id', 'report_order_id', 'lot_num', 'qty', 'material_no', 'creator_id', 'created_at', 'updated_at', 'deleted_at' ];

    /**
     * @var array
     */
    protected array $fields = ['id','report_order_id','lot_num','qty','material_no','created_at','updated_at'];

    /**
     * @var array
     */
    protected array $form = ['id','report_order_id','lot_num','qty','material_no','created_at','updated_at'];

    /**
     * @var array
     */
    public array $searchable = [
        'report_order_id' => '=',
        'lot_num' => '=',
        'material_no' => '=',

    ];

    /**
     * 时间格式化
     * @param $date
     * @return mixed
     */
    protected function serializeDate($date)
    {
        return $date->format('Y-m-d H:i');
    }

    /**
     * 关联生产汇报头信息
     * @return mixed
     */
    public function order(){
        return $this->belongsTo(ProductionReportOrder::class,'report_order_id');
    }

    /**
     * 关联物料信息
     * @return mixed
     */
    public function material(){
        return $this->hasOne(Material::class,'fnumber','material_no');
    }

    /**
     * 关联物料信息
     * @return mixed
     */
    public function box(){
        return $this->hasOne(BoxNumber::class,'code','lot_num');
    }



}
